// 我的医生列表
$(function() {
	initpersonalDoctor();
	initcollectDoctor();
	//专属医生
	function initpersonalDoctor() {
		var params = {
			"patientid":USERID	
		};
		userCenterModule.queryMyDoctorList(params, function(callBack) {
			console.log(callBack.length);
			if(callBack.length!=undefined){
				$(".personal-doctor").show();
				$(".no-collect").hide();
				for (i=0;i<callBack.length;i++) {
					var infors = callBack[i].doctor;
					var infor = infors;
					console.log(infor);
					if(infor.isfinevisit==0){
						$(".personal-doctor .personal-img").show();
						var showhtml= "";
						showhtml+="<div class=\"picture\"><img src=" +infor.avatar+ "></div>";
						showhtml+="<p class=\"doctorinfors font3\"><font class=\"name\">"+infor.realname+"</font> <font class=\"technical-offices\">"+infor.deptName+"</font></p>"
						showhtml+="<p class=\"doct font3\"><font class=\"doctortitle\">"+infor.doctortitle+"</font></p>";
						showhtml+="<p class=\"hospital font3\">"+infor.hospitalName+"</p>";
						
						var $skilful =infor.skilful;
						if(utilModule.checkUndefined($skilful)!="") {
							showhtml+="<p class=\"skilful font3\">擅长:"+$skilful+"</p>";
						}
						showhtml+="<div class=\"info font1\">";
							showhtml+="<p class='textC'>服务患者端次数:<span class=\"servicetimes\">"+infor.servicetimes+"</span></p>";
							showhtml+="<p class='textC'>关注人数:<span class=\"attention-num\">"+infor.concernnumber+"</span></p>";
						showhtml+="</div>";
						$(".personal-doctor .exclusive-doctor .personaldoctor").append(showhtml);
						$(".make-doctorList .personal-doctor").on("tap",function(){
							location.href ="doctor-details.html?doctorid="+infor.id;
						})
					}else{
						$(".personal-doctor").hide();
					}
				}
			}else{
				$(".personal-doctor").hide();
				
			}
		});
	}
	//收藏医生列表
	function  initcollectDoctor(){
		var params = {
			"patientid":USERID	
		};
		userCenterModule.myAdavate(params, function(data) {
			console.log(data);
			if(data.length!=undefined){
				$(".collect-doctor").show();
				$(".no-collect").hide();
				for (i=0;i<data.length;i++) {
					var infors = data[i].doctor;
					var infor = infors;
					console.log(infor);
					var showhtml= "";
					showhtml+="<li><div class=\"collectdoctor\"><div class=\"exclusive-doctor\" v="+infor.id+" >";
					showhtml+="<button v="+infor.id+" class='font1 cancel-collect'>取消收藏</button>"
					showhtml+="<div class=\"picture\"><img src=" +infor.avatar+ "></div>";
					showhtml+="<p class=\"doctorinfors font3\"><font class=\"name\">"+infor.realname+"</font> <font class=\"technical-offices\">"+infor.deptName+"</font></p>"
					showhtml+="<p class=\"doct font3\"><font class=\"doctortitle\">"+infor.doctortitle+"</font></p>";
					showhtml+="<p class=\"hospital font3\">"+infor.hospitalName+"</p>";
					var $skilful =infor.skilful;
						if(infor.skilful==undefined) {
							$skilful = " ";
						}
					showhtml+="<p class=\"skilful font3\">擅长:"+$skilful+"</p>";
					showhtml+="<div class=\"info font1\">";
						showhtml+="<p class='textC'>服务患者端次数:<span class=\"servicetimes\">"+infor.servicetimes+"</span></p>";
						showhtml+="<p class='textC'>关注人数:<span class=\"attention-num\">"+infor.concernnumber+"</span></p>";
					showhtml+="</div></div></div></li>";
					
					$(".collect-doctor").append(showhtml);
					
					$(".make-doctorList .collect-doctor .collectdoctor .exclusive-doctor").on("tap",function(){
						var doctorid = $(this).attr("v");
						console.log(doctorid);
						location.href ="doctor-details.html?doctorid="+doctorid;
					});

				}
			}
		});
	}
	$(".collect-doctor li .cancel-collect").on("tap",function(event){
		event.stopPropagation();
		var doctorId = $(this).attr("v");
		if(doctorId!="") {
			var params ={
				'patientid':USERID,
				"doctorid":doctorId
			}
			console.log(params);
			doctorModule.doctorAttention(params,function(callBack){ 
				console.log(callBack);
				if(callBack.msg=='关注成功'){
					console.log(888);
				}
	  			if(callBack.msg=='取消关注成功'){ 
	  				window.location.reload();	
	  			}

			})
		}
		
	})	
		
	document.getElementById('index').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../index.html',
    		id:'index',
		});
	});
	document.getElementById('message').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../html/inquiry/message-list.html',
    		id:'message',
		});
	});
	document.getElementById('article').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../html/article/article-list.html',
    		id:'article',
		});
	});
	document.getElementById('userCenter').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../html/userCenter/user-center.html',
    		id:'userCenter',
		});
	});
	
});



